<div class="row tab-content-row" id="metaGenObj_M_DIV">
  <div class="col-md-12">
      <div class="box box-primary">
        <div class="box-header">
          <h3 class="box-title">元对象列表</h3>
          <div class="box-tools pull-right">
            <form class="form-inline">
            <div class="input-group input-group-sm">
                <span class="input-group-addon">名称</span>
                <input type="text" class="form-control"  placeholder="对象名称" id="objName" name="objName">
            </div>
            <div class="input-group input-group-sm">
                <span class="input-group-addon">备注</span>
                <input type="text" class="form-control"  placeholder="对象备注" id="objComment" name="objComment">
            </div>
            <div class="btn-group" >
                <button type="button" class="btn  btn-success btn-sm" data-btntype="search">查询</button>
                <button type="button" class="btn  btn-warning btn-sm" data-btntype="reset">重置</button>
            </div>
            <div class="btn-group" >
                <button type="button" class="btn  btn-success btn-sm" data-btntype="add">新增</button>
                <button type="button" class="btn  btn-warning btn-sm" data-btntype="edit" data-position="tool">修改</button>
                <button type="button" class="btn  btn-warning btn-sm" data-btntype="delete" data-position="tool">删除</button>
            </div>
            </form>
          </div>
        </div>
        <!-- /.box-header -->
        <div class="box-body table-responsive ">
          <table class="table table-bordered table-condensed table-striped mytable " id="metaGenObjTable"></table>
        </div>
        <!-- /.box-body -->
        <div class="box-footer box-footer-condensed clearfix">
          <div class=" no-margin-top">
            <span class="pagination_record_title" id="prt_metaGenObjPage"></span>
            <ul class="pagination  pagination-sm pull-right no-margin pagination_ul" id="prl_metaGenObjPage" ></ul>
          </div>
        </div>
          <!-- /.box-footer -->
      </div>
      <!-- /.box -->
  </div>
  <!-- /.col-md-12 -->
  <div class="modal fade" id="metaGenObj_A_Model" data-reftableid="metaGenObjTable"></div> 
  <div class="modal fade" id="metaGenObj_E_Model" data-reftableid="metaGenObjTable"></div>
  
</div>
<!-- 该DIV 为另外关联的对象管理,不适宜放在本模块DIV之中,作为自己的兄弟结点中-->
<div class="modal fade" id="metaGenAttrs_M_Model" ></div>

<script>
  require([ "jquery","bootbox", "bootstrap", "bootstrapTable","bootstrapTab_CH","validate"],function($, bootbox) {
    var container = $("#metaGenObj_M_DIV");
    container.triggerManageAttrsView = function(id){
      container.parent().find("#metaGenAttrs_M_Model").load('${contextPath}/metaGenObj/g2ObjAttrsManage/'+id,{},
        function(responseTxt,statusTxt,xhr){
            if(statusTxt=="success"){
                container.parent().find("#metaGenAttrs_M_Model").modal({
                    backdrop:'static',
                    keyboard: false,
                    show:true
                });
                
            }  
            if(statusTxt=="error"){
              frameworkOptions.showInfoMessages(xhr);
            }     
        });
    }
    container.triggerDelete = function(ids){
      $.ajax({
              type: "POST",
              url: "${contextPath}/metaGenObj/delete",
              dataType:"json",
              async: false,
              contentType:"application/json",
              data:JSON.stringify(ids),
              //data:{ids},
              success: function(data){
                  if("success" == data.status){
                    frameworkOptions.showSuccessMessages(data.message); 
                    container.find('#metaGenObjTable').bootstrapTable('refresh'); 
                    
                  }else if("failure" == data.status){
                    frameworkOptions.showErrorMessages(data.message);
                  }
              }
          }); 
    }
    container.triggerEditView = function(id){
      container.find("#metaGenObj_E_Model").load('${contextPath}/metaGenObj/g2Edit/'+id,{},
        function(responseTxt,statusTxt,xhr){
            if(statusTxt=="success"){
                container.find("#metaGenObj_E_Model").modal({
                    backdrop:false,
                    show:true
                });
            }  
            if(statusTxt=="error"){
              frameworkOptions.showInfoMessages(xhr);
            }     
        });
    }
    container.triggerAddView = function(){
      container.find("#metaGenObj_A_Model").load('${contextPath}/metaGenObj/g2Add/',{},
        function(responseTxt,statusTxt,xhr){
            if(statusTxt=="success"){
                container.find("#metaGenObj_A_Model").modal({
                    backdrop:false,
                    show:true
                });
            }  
            if(statusTxt=="error"){
              frameworkOptions.showInfoMessages(xhr);
              
            }     
        });
    }  
    container.find('#metaGenObjTable').bootstrapTable(
      {
        url : "${contextPath}/metaGenObj/queryList",
        dataType : "json",
        contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
        pagination : true, //分页
        dataField : 'data.rows',
        method: "POST",
        noToolBar : true,//新增 是否不显示原生的工具栏 
        customPagination : true,//新增 是否启用自定义分页
        customPaginationTitleSelector : "#prt_metaGenObjPage", //新增 客户分页统计信息容器的JQUERY选择器
        customPaginationListSelector : "#prl_metaGenObjPage", //新增 客户分页条的JQUERY选择器 
        queryParams : function(params) {
          return {
            pageSize :(params.limit || 10),
            pageNum : (params.offset || 1),
            objName : container.find('#objName').val().trim(),
            objComment : container.find('#objComment').val().trim()
          }
        },
        singleSelect : false,
        //search : true, //显示搜索框
        sidePagination : "server", //服务端处理分页
        columns : [
            {
              field : 'id',
              align : 'center',
              width : 30,
              title : '<label class="mylabel"></label>',
              formatter : function(value,row, index) {
                var checkbox = '<label class="mylabel" id="'+value+'"></label>';
                return checkbox;
              }
            },

            {
              title : '名称',
              field : 'objName',
              align : 'left',
              valign : 'middle'
            },
            {
              title : '备注',
              field : 'objComment',
              align : 'left',
              valign : 'middle',
            },
            {
              title : '包路径',
              field : 'objPackageName',
              align : 'left'
            },
            {
              title : '完整类名',
              field : 'objTypeName',
              align : 'left'
            },
            {
              title : '操作',
              field : 'id',
              width :  200,
              align : 'center',
              formatter : function(value,row, index) {
                var d = '<a href="#"  class="refAttr" data-rowid="'+row.id+'">属性管理</a>|<a href="#" mce_href="#" class="delOne" id="'+row.id+'">删除</a> ';
                var d = '<a href="#" data-btntype="attrManager" data-position="row" data-rowid="'+row.id+'"><span  class="badge bg-light-blue"><i class="fa  fa-cogs" >属性管理</i></span></a><a href="#" data-btntype="edit" data-position="row" data-rowid="'+row.id+'"><span  class="badge bg-yellow"><i class="fa  fa-edit" >编辑</i></span></a><a href="#" data-btntype="delete" data-position="row" data-rowid="'+row.id+'"><span  class="badge bg-red"><i class="fa  fa-remove" >删除</i></span> </a>';
                return d;
              }
            } ]
    });
    
    container.on('click','[data-btntype="edit"]',function(e){
        if($(e.currentTarget).data('position') == "row"){
          container.triggerEditView($(e.currentTarget).data('rowid'));
        }else{
          if(container.find('#metaGenObjTable').bootstrapTable('getSelections').length==1){
            container.triggerEditView(container.find('#metaGenObjTable').bootstrapTable('getSelections')[0].id);
          }else{
            frameworkOptions.showInfoMessages("请选择一条记录");
              
          }
        }
    });
    container.on('click','[data-btntype="attrManager"]',function(e){
      var id = $(e.currentTarget).data('rowid');
      container.triggerManageAttrsView(id);
    });
    container.on('click','button[data-btntype="add"]',function(e){
      container.triggerAddView();
    });
    container.on('click','button[data-btntype="search"]',function(e){
      container.find('#metaGenObjTable').bootstrapTable('refresh');
    });
    container.on('click','[data-btntype="delete"]',function(e){
        var ids = new Array();
        if($(e.currentTarget).data('position') == "row"){
          ids.push($(e.currentTarget).data('rowid'));
        }else{
          if(container.find('#metaGenObjTable').bootstrapTable('getSelections').length>0){
            $.each(container.find('#metaGenObjTable').bootstrapTable('getSelections'),function(index,obj){
              ids.push(obj.id);   
            });
          }else{
            frameworkOptions.showInfoMessages("请选择记录");
              
          }
        }
        if(ids && ids.length>0){
          bootbox.confirm({
                message: "你确定要删除该元对象吗?",
                buttons: {
                  confirm: {
                     label: "确定",
                     className: "btn-primary btn-sm",
                  },
                  cancel: {
                     label: "取消",
                     className: "btn-default btn-sm",
                  }
                },
                callback: function(result) {
                    if(result) {
                        container.triggerDelete(ids);
                    }
                }
            });
        }
    });
    
  });
</script>